package com.ccbooks.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import com.ccbooks.view.R;
import com.ccbooks.view.R.string;
import com.ccbooks.vo.CatelogItem;

import android.app.Activity;
import android.hardware.Camera.Size;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CatelogAdapter extends BaseAdapter {

	public Activity activity;
	public List<CatelogItem> items;
	private LayoutInflater inflater;

	public CatelogAdapter(Activity activity, List<CatelogItem> items) {
		super();
		this.activity = activity;
		this.items = items;
		inflater = LayoutInflater.from(activity);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (items != null) {
			return items.size();
		}
		return 0;
	}

	@Override
	public CatelogItem getItem(int position) {
		// TODO Auto-generated method stub
		if (items != null) {
			return items.get(position);
		}
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		if(items != null){
			return items.get(position).id;
		}else{
			return 0;
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		RelativeLayout ly = null;
		if (items != null) {
			ly = (RelativeLayout) inflater.inflate(R.layout.catelogitem, null);
			TextView tvChaptersTitle = (TextView) ly
					.findViewById(R.id.tvChaptersTitle);
			TextView tvChaptersPage = (TextView) ly
					.findViewById(R.id.tvChaptersPage);
			TextView tvChapterDate = (TextView) ly
					.findViewById(R.id.tvChapterDate);

			tvChaptersTitle.setText(getItem(position).title);
			tvChaptersPage.setText(String.valueOf(getItem(position).pageIndex));
			if (getItem(position).date != 0) {
				tvChapterDate.setText(String.valueOf(getItem(position).date));
			}
		}
		return ly;
	}

}
